<!--
@license
Copyright (C) 2017 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../bower_components/iron-autogrow-textarea/iron-autogrow-textarea.html">
<link rel="import" href="../../../bower_components/iron-input/iron-input.html">
<link rel="import" href="../../../styles/gr-form-styles.html">
<link rel="import" href="../../../styles/gr-subpage-styles.html">
<link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../shared/gr-autocomplete/gr-autocomplete.html">
<link rel="import" href="../../shared/gr-copy-clipboard/gr-copy-clipboard.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
<link rel="import" href="../../shared/gr-select/gr-select.html">

<dom-module id="gr-group">
  <template>
    <style include="shared-styles"></style>
    <style include="gr-subpage-styles">
      h3.edited:after {
        color: var(--deemphasized-text-color);
        content: ' *';
      }
      .inputUpdateBtn {
        margin-top: .3em;
      }
    </style>
    <style include="gr-form-styles"></style>
    <main class="gr-form-styles read-only">
      <div id="loading" class$="[[_computeLoadingClass(_loading)]]">
        加载中...
      </div>
      <div id="loadedContent" class$="[[_computeLoadingClass(_loading)]]">
        <h1 id="Title">[[_groupName]]</h1>
        <h2 id="configurations">常规</h2>
        <div id="form">
          <fieldset>
            <h3 id="groupUUID">群组 UUID</h3>
            <fieldset>
              <gr-copy-clipboard
                  text="[[_groupConfig.id]]"></gr-copy-clipboard>
            </fieldset>
            <h3 id="groupName" class$="[[_computeHeaderClass(_rename)]]">
              群组组名
            </h3>
            <fieldset>
              <span class="value">
                <gr-autocomplete
                    id="groupNameInput"
                    text="{{_groupConfig.name}}"
                    disabled="[[_computeGroupDisabled(_groupOwner, _isAdmin, _groupIsInternal)]]"></gr-autocomplete>
              </span>
              <span class="value" disabled$="[[_computeGroupDisabled(_groupOwner, _isAdmin, _groupIsInternal)]]">
                <gr-button
                    id="inputUpdateNameBtn"
                    on-tap="_handleSaveName"
                    disabled="[[!_rename]]">
                  修改组名</gr-button>
              </span>
            </fieldset>
            <h3 class$="[[_computeHeaderClass(_owner)]]">
              群组所有者
            </h3>
            <fieldset>
              <span class="value">
                <gr-autocomplete
                    id="groupOwnerInput"
                    text="{{_groupConfig.owner}}"
                    value="{{_groupConfigOwner}}"
                    query="[[_query]]"
                    disabled="[[_computeGroupDisabled(_groupOwner, _isAdmin, _groupIsInternal)]]">
                </gr-autocomplete>
              </span>
              <span class="value" disabled$="[[_computeGroupDisabled(_groupOwner, _isAdmin, _groupIsInternal)]]">
                <gr-button
                    on-tap="_handleSaveOwner"
                    disabled="[[!_owner]]">
                  修改所有者</gr-button>
              </span>
            </fieldset>
            <h3 class$="[[_computeHeaderClass(_description)]]">
              群组简介
            </h3>
            <fieldset>
              <div>
                <iron-autogrow-textarea
                    class="description"
                    autocomplete="on"
                    bind-value="{{_groupConfig.description}}"
                    disabled="[[_computeGroupDisabled(_groupOwner, _isAdmin, _groupIsInternal)]]"></iron-autogrow-textarea>
              </div>
              <span class="value" disabled$="[[_computeGroupDisabled(_groupOwner, _isAdmin, _groupIsInternal)]]">
                <gr-button
                    on-tap="_handleSaveDescription"
                    disabled="[[!_description]]">
                  保存简介
                </gr-button>
              </span>
            </fieldset>
            <h3 id="options" class$="[[_computeHeaderClass(_options)]]">
              其他设置
            </h3>
            <fieldset id="visableToAll">
              <section>
                <span class="title">
                  使群组对所有注册用户可见
                </span>
                <span class="value">
                  <gr-select
                      id="visibleToAll"
                      bind-value="{{_groupConfig.options.visible_to_all}}">
                    <select disabled$="[[_computeGroupDisabled(_groupOwner, _isAdmin, _groupIsInternal)]]">
                      <template is="dom-repeat" items="[[_submitTypes]]">
                        <option value="[[item.value]]">[[item.label]]</option>
                      </template>
                    </select>
                  </gr-select>
                </span>
              </section>
              <span class="value" disabled$="[[_computeGroupDisabled(_groupOwner, _isAdmin, _groupIsInternal)]]">
                <gr-button
                    on-tap="_handleSaveOptions"
                    disabled="[[!_options]]">
                  保存修改
                </gr-button>
              </span>
            </fieldset>
          </fieldset>
        </div>
      </div>
    </main>
    <gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
  </template>
  <script src="gr-group.js"></script>
</dom-module>
